package com.bjesc_b2c.app.appraiset.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.bjesc_b2c.app.appraiset.R;

import java.util.List;

import app.pinggushi.bjesc.com.baserecyclerview.adapter.CommonAdapter;
import app.pinggushi.bjesc.com.baserecyclerview.adapter.base.ViewHolder;
import master_bean.ToDayBean;

import static com.bjesc_b2c.app.appraiset.R.id.tv_adjustment_status;
import static com.bjesc_b2c.app.appraiset.R.id.tv_car_dealers;

/**
 * Created by lenovo on 2017/2/27.
 */

public class UploadHistoryAdapter extends CommonAdapter<ToDayBean> {
    private statusListener statusListener;

    public UploadHistoryAdapter(Context context, int layoutId, List<ToDayBean> datas) {
        super(context, layoutId, datas);
    }

    public void setSListener(statusListener statusListener) {
        this.statusListener = statusListener;
    }

    @Override
    protected void convertView(ViewHolder holder, ToDayBean o, final int position) {
        holder.setVisible(tv_adjustment_status,true);
        if (!TextUtils.isEmpty(o.getImg_url())) {
            if (o.getImg_url().contains("http")) {
                holder.setFrescoUrl(R.id.tv_car_photo, o.getImg_url(), true);
            } else {
                holder.setFrescoFile(R.id.tv_car_photo, o.getImg_url(), true);
            }
        }
        if (!TextUtils.isEmpty(o.getDealer_name())) {
            holder.setText(tv_car_dealers, "车行名称：" + o.getDealer_name());
        }

        if (!TextUtils.isEmpty(o.getCarspec_name())) {
            holder.setText(R.id.tv_car_type, "车型：" + o.getSeries_name() + " " + o.getCarspec_name());
        }
        String type = o.getStatus_type();
        String txtType = "";
        if (!TextUtils.isEmpty(type)) {
            if (o.getStatus_type().equals("TRACK")) {
                txtType = "线索";
                holder.setVisible(tv_adjustment_status,false);
            } else if (type.equals("EXAMINING")) {
                txtType = "总部待审";
            } else if (type.equals("KENTNOPASS")) {
                txtType = "总部不通过";
            } else if (type.equals("PUBLISHPASS")) {
                txtType = "上架";
            } else if (type.equals("ENDDOWN")) {
                txtType = "下架";
            } else if (type.equals("COMMUNICATED")) {
                txtType = "内部交流";
            }
            holder.setText(R.id.tv_car_status, "状态：" + txtType);
        }

        if (!TextUtils.isEmpty(o.getOwner_price())) {
            holder.setText(R.id.tv_car_price, o.getOwner_price());
        }
        holder.setOnClickListener(tv_adjustment_status, new View.OnClickListener() {//调价
            @Override
            public void onClick(View v) {
                if (statusListener != null) {
                    statusListener.adjustment(position);
                }
            }
        });
        holder.setOnClickListener(R.id.tv_off_status, new View.OnClickListener() {//下架
            @Override
            public void onClick(View v) {
                if (statusListener != null) {
                    statusListener.offShelf(position);
                }
            }
        });
    }

    public interface statusListener {
        void adjustment(int position);

        void offShelf(int position);
    }
}
